package com.zhidisoft.crm.controller.auth;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zhidisoft.crm.service.ISysFuncService;
import com.zhidisoft.crm.service.ISysRoleFuncService;
import com.zhidisoft.crm.service.ISysRoleService;

@Controller
@RequestMapping("/auth/func")
public class RoleFuncController {
	@Autowired
	ISysFuncService iSysFuncService;
	
	@Autowired
	ISysRoleService roleService; 
	
	@Autowired
	ISysRoleFuncService roleFuncService;
	
	@GetMapping("list/{roleId}")
	public ModelAndView save(@PathVariable(name="roleId")String roleId) {
		ModelAndView modelAndView=new ModelAndView("auth/func/rolefunc.html");
		modelAndView.addObject("role", roleService.selectById(roleId));
		modelAndView.addObject("funcList", iSysFuncService.findAll());
		return modelAndView;
	}
	
	@PostMapping("list/{roleId}")
	public String list( 
			@PathVariable(name="roleId")String roleId,String[] funcIds) {
		roleFuncService.save(roleId, funcIds);
		return "redirect:/auth/role/list";
	}
}
